$(document).ready(function() {
	
	if($('#component').length == 1) {
		var editor = CodeMirror.fromTextArea(document.getElementById("component"), {mode: "text/html", tabMode: "indent"});
		
		$('#edit_component_save_button').bind('click', function(){
			editor.save();
			
			var oData = {
				'component_id' : $('#component_id').val(), 
				'component_name' : $('#component_name').val(), 
				'component' : $('#component').val()
			};
			
			$.post('/admin/components_ajax/save_component', oData, function(data){
				if(data.iComponentId) {
					$('#component_id').val(data.iComponentId);
				}
			}, 'json');
		});
	}
	
});